package top.alanshelby.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Mybatis测试类
 */
public class MybatisTest {

    public static void main(String[] args) throws IOException {
        Dept dept = new Dept();
        dept.setDeptno(1002);
        dept.setDname("技术研发部");
        dept.setLoc("测试");
        InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = factory.openSession();
        sqlSession.insert("insertDept", dept);
        sqlSession.commit();
    }

}
